package com.ggy.ggyaicodemother.core.saver;

import cn.hutool.core.util.StrUtil;
import com.ggy.ggyaicodemother.ai.model.MultiFileCodeResult;
import com.ggy.ggyaicodemother.exception.BusinessException;
import com.ggy.ggyaicodemother.exception.ErrorCode;
import com.ggy.ggyaicodemother.model.enums.CodeGenTypeEnum;

public class MultiFileCodeFileSaverTemplate extends CodeFileSaverTemplate<MultiFileCodeResult>{
    @Override
    protected CodeGenTypeEnum getCOdeType() {
        return CodeGenTypeEnum.MULTI_FILE;
    }

    @Override
    protected void saveFiles(MultiFileCodeResult result, String baseDirPath) {
        //保存 HTML 文件
        writeToFile(baseDirPath,"index.html",result.getHtmlCode());
        //保存 CSS 文件
        writeToFile(baseDirPath,"style.css", result.getCssCode());
        //保存 js 代码
        writeToFile(baseDirPath,"script.js", result.getJsCode());
    }

    @Override
    protected void validateInput(MultiFileCodeResult result) {
        super.validateInput(result);
        //至少要有 HTML 代码，CSS 和JS可以为空
        if(StrUtil.isBlank(result.getHtmlCode())){
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"html代码内容不能为空");
        }
    }
}













